package com.xianbeiying.app.ckgl.data;

import com.lidroid.xutils.util.LogUtils;
import com.xianbeiying.app.ckgl.adapter.PopWindowChoiceWpAdapter;
import com.xianbeiying.app.ckgl.bean.DevicesBean;
import com.xianbeiying.app.ckgl.bean.FaMenBean;
import com.xianbeiying.app.ckgl.bean.FaMenTypeBean;
import com.xianbeiying.app.ckgl.bean.SysConfigssBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 模拟数据
 */
public class DataUtil {
    //大棚数量
  public static String [] dapeng={"1","2","3","4","5","6","7","8","9"};
    //阀门数
    public static String [] famen={"1","2","3","4","5","6"};
    //风机数
    public static String [] fenji={"1","2","3","4","5","6","7","8"};
    //卷帘数
    public static String [] juanlian={"1","2","3","4","5","6","7","8","9","10"};
    //加热器数
    public static String [] szlight={"1","2","3","4","5","6","7","8","9","10"};

  /**
   * 普通的方法去除list中重复的数据
   */
  public static ArrayList<String> getRListData(ArrayList<String> list){
    for (int i = 0; i < list.size() - 1; i++) {
      for (int j = list.size() - 1; j > i; j--) {
        if (list.get(j).equals(list.get(i))) {
          list.remove(j);
        }
      }
    }
    return list;
  }

  public static List<SysConfigssBean> getDean(List<SysConfigssBean> list){
    for (int i = 0; i < list.size() - 1; i++) {
      for (int j = list.size() - 1; j > i; j--) {
        if (list.get(j).getPlantType()==list.get(i).getPlantType()&&
                list.get(j).getCropId()==list.get(i).getCropId()) {
          list.remove(j);
        }
      }
    }
    return list;
  }
  public static boolean isStringRest(ArrayList<String> list,String str){
    int size=list.size();
    boolean is=false;
    if(list.size()==0){
      return  false;
    }
    for (int i=0;i<size;i++){
      if(list.get(i).equals(str)){
        is=true;
        break;
      }
    }
    return is;
  }

  //通过首部获取阀门设置信息
  public   static ArrayList<DevicesBean.DEVICESBean>  getFanMenss(DevicesBean devicesBean,int id){
    ArrayList<DevicesBean.DEVICESBean> alldevicesBeen=new ArrayList<>();
    alldevicesBeen.clear();
    if(devicesBean!=null){
      int size1=devicesBean.getGREENHOUSE().size();
      int size2=devicesBean.getDEVICES().size();
      LogUtils.e(size1+"-----"+size2);
//      for(int i=0;i<size1;i++){
          for(int j=0;j<size2;j++){
              if(devicesBean.getGREENHOUSE().get(id).getGreenhouseId()==devicesBean.getDEVICES().get(j).getGreenhouseid()&&
                      devicesBean.getDEVICES().get(j).getDevicetype()==-128){
                DevicesBean.DEVICESBean devicesBean1=new DevicesBean.DEVICESBean();
                devicesBean1.setSystemid(devicesBean.getDEVICES().get(j).getSystemid());
                devicesBean1.setGreenhouseid(devicesBean.getDEVICES().get(j).getGreenhouseid());
                alldevicesBeen.add(devicesBean1);

              }

          }
//      }
    }
    LogUtils.e(alldevicesBeen.size()+"------1111110000000");

    return  alldevicesBeen;

  }
//获取阀门信息
  public   static ArrayList<DevicesBean.ALLDEVICESBean>  getFanMen(DevicesBean devicesBean,int id){
    ArrayList<DevicesBean.ALLDEVICESBean> alldevicesBeen=new ArrayList<>();
    ArrayList<DevicesBean.DEVICESBean> devicesBeanArrayList=getFanMenss(devicesBean,id);
    alldevicesBeen.clear();
    if(devicesBean!=null){
      int size1=devicesBean.getALLDEVICES().size();
      int size2=devicesBeanArrayList.size();
      LogUtils.e(size1+"------"+size2);
      for(int i=0;i<size2;i++){
        for(int j=0;j<size1;j++){
          if(devicesBeanArrayList.get(i).getSystemid()==devicesBean.getALLDEVICES().get(j).getSystemid()){
            if(devicesBean.getALLDEVICES().get(j).getDevicetype()
                    ==0||devicesBean.getALLDEVICES().get(j).getDevicetype()==1){
              LogUtils.e(devicesBeanArrayList.get(i).getSystemid()+"----"+devicesBean.getALLDEVICES().get(j).getSystemid());
              LogUtils.e(devicesBean.getALLDEVICES().get(j).getDevicetype()+"=======");
              DevicesBean.ALLDEVICESBean alldevicesBean=new DevicesBean.ALLDEVICESBean();
              alldevicesBean.setGreenhouseid(devicesBean.getALLDEVICES().get(j).getGreenhouseid());
              alldevicesBean.setSystemid(devicesBean.getALLDEVICES().get(j).getSystemid());
              alldevicesBean.setCtrlid(devicesBean.getALLDEVICES().get(j).getCtrlid());
              alldevicesBean.setDevicedn(devicesBean.getALLDEVICES().get(j).getDevicedn());
              alldevicesBean.setDeviceid(devicesBean.getALLDEVICES().get(j).getDeviceid());
              alldevicesBean.setDevicetype(devicesBean.getALLDEVICES().get(j).getDevicetype());
              alldevicesBean.setName(devicesBean.getALLDEVICES().get(j).getName());
              alldevicesBean.setRemark(devicesBean.getALLDEVICES().get(j).getRemark());
              alldevicesBean.setStatus(devicesBean.getALLDEVICES().get(j).getStatus());
              alldevicesBeen.add(alldevicesBean);
            }
          }
        }

      }
    }

    LogUtils.e(alldevicesBeen.size()+"------0000000");

    return  alldevicesBeen;

  }

  public static String [] getFamenss(ArrayList<DevicesBean.ALLDEVICESBean> fanmens){
    if(fanmens!=null){
      int size=fanmens.size();
      String [] con=new String[size];
      for(int i=0;i<size;i++){
        con[i]=(i+1)+"";
      }
      return con;
    }
    return null;
  }

  /**
   * 获取加热器接口
   * */
  public   static  ArrayList<FaMenBean.VBean.STATUSBean> healers(FaMenBean faMenBean,int selectID){
    ArrayList<FaMenBean.VBean.STATUSBean> arrayList=new ArrayList<>();
    arrayList.clear();
    if (faMenBean!=null){
      int size=faMenBean.getV().getSTATUS().size();
      for(int i=0;i<size;i++){
        if(selectID==0){
          if(faMenBean.getV().getSTATUS().get(i).getDEVTYPE()==6){
            FaMenBean.VBean.STATUSBean vBean=new FaMenBean.VBean.STATUSBean();
            vBean.setSYSTEMID(faMenBean.getV().getSTATUS().get(i).getSYSTEMID());
            vBean.setCTRLID(faMenBean.getV().getSTATUS().get(i).getCTRLID());
            vBean.setDEVID(faMenBean.getV().getSTATUS().get(i).getDEVID());
            vBean.setDEVSTATUS(faMenBean.getV().getSTATUS().get(i).getDEVSTATUS());
            vBean.setDEVTYPE(faMenBean.getV().getSTATUS().get(i).getDEVTYPE());
            vBean.setNAME(faMenBean.getV().getSTATUS().get(i).getNAME());
            arrayList.add(vBean);}
        }else{
          if(faMenBean.getV().getSTATUS().get(i).getDEVTYPE()==6){
            FaMenBean.VBean.STATUSBean vBean=new FaMenBean.VBean.STATUSBean();
            vBean.setSYSTEMID(faMenBean.getV().getSTATUS().get(i).getSYSTEMID());
            vBean.setCTRLID(faMenBean.getV().getSTATUS().get(i).getCTRLID());
            vBean.setDEVID(faMenBean.getV().getSTATUS().get(i).getDEVID());
            vBean.setDEVSTATUS(faMenBean.getV().getSTATUS().get(i).getDEVSTATUS());
            vBean.setDEVTYPE(faMenBean.getV().getSTATUS().get(i).getDEVTYPE());
            vBean.setNAME(faMenBean.getV().getSTATUS().get(i).getNAME());
            arrayList.add(vBean);}
        }

      }
    }
    return  arrayList;
  };

  /**
   * 获取除湿器接口
   * */
  public   static  ArrayList<FaMenBean.VBean.STATUSBean> fanmens(FaMenBean faMenBean,int selectID){
    ArrayList<FaMenBean.VBean.STATUSBean> arrayList=new ArrayList<>();
    arrayList.clear();
    if (faMenBean!=null){
     int size=faMenBean.getV().getSTATUS().size();
     for(int i=0;i<size;i++){
       if(selectID==0){
          if(faMenBean.getV().getSTATUS().get(i).getDEVTYPE()==7){
            FaMenBean.VBean.STATUSBean vBean=new FaMenBean.VBean.STATUSBean();
            vBean.setSYSTEMID(faMenBean.getV().getSTATUS().get(i).getSYSTEMID());
            vBean.setCTRLID(faMenBean.getV().getSTATUS().get(i).getCTRLID());
            vBean.setDEVID(faMenBean.getV().getSTATUS().get(i).getDEVID());
            vBean.setDEVSTATUS(faMenBean.getV().getSTATUS().get(i).getDEVSTATUS());
            vBean.setDEVTYPE(faMenBean.getV().getSTATUS().get(i).getDEVTYPE());
            vBean.setNAME(faMenBean.getV().getSTATUS().get(i).getNAME());
            arrayList.add(vBean);}
          }else{
         if(faMenBean.getV().getSTATUS().get(i).getDEVTYPE()==7){
           FaMenBean.VBean.STATUSBean vBean=new FaMenBean.VBean.STATUSBean();
           vBean.setSYSTEMID(faMenBean.getV().getSTATUS().get(i).getSYSTEMID());
           vBean.setCTRLID(faMenBean.getV().getSTATUS().get(i).getCTRLID());
           vBean.setDEVID(faMenBean.getV().getSTATUS().get(i).getDEVID());
           vBean.setDEVSTATUS(faMenBean.getV().getSTATUS().get(i).getDEVSTATUS());
           vBean.setDEVTYPE(faMenBean.getV().getSTATUS().get(i).getDEVTYPE());
           vBean.setNAME(faMenBean.getV().getSTATUS().get(i).getNAME());
           arrayList.add(vBean);}
       }

     }
    }
    return  arrayList;
  };

  /**
   * 获取阀门接口
   * */
  public   static  ArrayList<FaMenBean.VBean.STATUSBean> getSeBei(FaMenBean faMenBean,int typeId){
    ArrayList<FaMenBean.VBean.STATUSBean> arrayList=new ArrayList<>();
    arrayList.clear();
    if (faMenBean!=null&&faMenBean.getV()!=null){
      int size=faMenBean.getV().getSTATUS().size();
      for(int i=0;i<size;i++){
        if(faMenBean.getV().getSTATUS().get(i).getDEVTYPE()==typeId){
          FaMenBean.VBean.STATUSBean vBean=new FaMenBean.VBean.STATUSBean();
          vBean.setSYSTEMID(faMenBean.getV().getSTATUS().get(i).getSYSTEMID());
          vBean.setCTRLID(faMenBean.getV().getSTATUS().get(i).getCTRLID());
          vBean.setDEVID(faMenBean.getV().getSTATUS().get(i).getDEVID());
          vBean.setNAME(faMenBean.getV().getSTATUS().get(i).getNAME());
          vBean.setDEVSTATUS(faMenBean.getV().getSTATUS().get(i).getDEVSTATUS());
          vBean.setDEVTYPE(faMenBean.getV().getSTATUS().get(i).getDEVTYPE());
          arrayList.add(vBean);
        }

      }
    }
    return  arrayList;
  };


  public static String [] getFamen(ArrayList<FaMenBean.VBean.STATUSBean> fanmens){
    if(fanmens!=null){
      int size=fanmens.size();
      String [] con=new String[size];
      for(int i=0;i<size;i++){
        con[i]=(i+1)+"";
      }
      return con;
    }
    return null;
    }
  //获取选中的数据  ;
  public static   ArrayList<String> choiceList(PopWindowChoiceWpAdapter wp_mchoice_fmAdapter,String[] conts){
    ArrayList<String> vaAutoList = new ArrayList<>();
    vaAutoList.clear();
    int size = wp_mchoice_fmAdapter.getIsBoolean().size();
    for (int i = 0; i < size; i++){
      if (wp_mchoice_fmAdapter.getIsBoolean().get(i)) {
        vaAutoList.add(conts[i] + "");
      }
    }
    return  DataUtil.getRListData(vaAutoList);
  }

  //获取选中的数据  ArrayList<FaMenBean.VBean.STATUSBean> listFa;
  public static   ArrayList<String> choiceSeBieList(PopWindowChoiceWpAdapter wp_mchoice_fmAdapter,ArrayList<FaMenBean.VBean.STATUSBean> listFa){
    ArrayList<String> vaAutoList = new ArrayList<>();
    vaAutoList.clear();
    int size = wp_mchoice_fmAdapter.getIsBoolean().size();
    for (int i = 0; i < size; i++){
      if (wp_mchoice_fmAdapter.getIsBoolean().get(i)) {
        vaAutoList.add(listFa.get(i).getNAME() + "");
      }
    }
    return  DataUtil.getRListData(vaAutoList);
  }
  //阀门状态参数获取
  public static  String [] getFmOc(FaMenTypeBean faMenTypeBean){
    int size = faMenTypeBean.getV().getEQPS().size();
    String [] fmType = new String[size];
    for (int i = 0; i < size; i++) {
      if (faMenTypeBean.getV().getEQPS().get(i).getSTATE() == 0) {
        fmType[i] = "停止";
      } else if (faMenTypeBean.getV().getEQPS().get(i).getSTATE() == 100) {
        fmType[i] = "运行";
      } else {
        fmType[i] = "未知";
      }
    }
    return fmType;
  }

  public static  String [] getFmOcc( ArrayList<FaMenBean.VBean.STATUSBean> fanmens){
    int size = fanmens.size();
    String [] fmType = new String[size];
    for (int i = 0; i < size; i++){
      if (fanmens.get(i).getDEVSTATUS()==0){
        fmType[i] = "停止";
      } else if (fanmens.get(i).getDEVSTATUS()==100) {
        fmType[i] = "运行";
      } else {
        fmType[i] = "未知";
      }
    }
    return fmType;
  }
  //设置选择框的内容
  public static void setBooleanArray(PopWindowChoiceWpAdapter wp_achoice_Adapter,int position){
    int size = wp_achoice_Adapter.getIsBoolean().size();
    for (int i = 0; i < size; i++){
      if (i == position){
        wp_achoice_Adapter.getIsBoolean().set(position, true);
      }else{
        wp_achoice_Adapter.getIsBoolean().set(i, false);
      }
    }
  }
  //设置阀门周期选择框的内容
  public static void setZqBooleanArray(PopWindowChoiceWpAdapter wp_achoice_Adapter,int position){
    if (wp_achoice_Adapter.getIsBoolean().get(position)) {
      wp_achoice_Adapter.getIsBoolean().set(position, false);
    } else {
      wp_achoice_Adapter.getIsBoolean().set(position, true);
    }
  }
}
